home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 8605 / 8605.xpi / chrome / content / utils.js < prev   
Text File  |  2009-02-01  |  3KB  |  94 lines

  1. function deviantAnywhereUtils()
  2. {
  3.     this.boolPref = 1;
  4.     this.intPref = 2;
  5.     this.stringPref = 3;
  6. }
  7.  
  8. deviantAnywhereUtils.prototype =
  9. {
  10.     getUserData: function()
  11.     {
  12.         try
  13.         {
  14.             var myLoginManager = Components.classes["@mozilla.org/login-manager;1"].getService(Components.interfaces.nsILoginManager);
  15.             var logins = myLoginManager.findLogins({}, "chrome://deviantAnywhere", "User auto-login", null);
  16.             for (var i = 0; i < logins.length; i++)
  17.               if (logins[i].username == "Main User")
  18.                  return logins[i];
  19.         }
  20.         catch(e)
  21.         {
  22.             return null;
  23.         }
  24.         return null;
  25.     },
  26.  
  27.     getPref: function(prefName,prefType)
  28.     {
  29.         var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
  30.         branch = prefs.getBranch("deviantAnywhere.");
  31.         try
  32.         {
  33.             if (prefType==this.boolPref)
  34.                 return branch.getBoolPref(prefName);
  35.             else
  36.             if (prefType==this.intPref)
  37.                 return branch.getIntPref(prefName);
  38.             else
  39.                 return branch.getCharPref(prefName);
  40.         }
  41.         catch(e)
  42.         {
  43.             return null;
  44.         }
  45.     },
  46.  
  47.     setPref: function(prefName, prefValue, prefType)
  48.     {
  49.         var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
  50.  
  51.         if (prefType==this.boolPref)
  52.             prefs.setBoolPref("deviantAnywhere."+prefName,prefValue);
  53.         else
  54.         if (prefType==this.intPref)
  55.             prefs.setIntPref("deviantAnywhere."+prefName,prefValue);
  56.         else
  57.             prefs.setCharPref("deviantAnywhere."+prefName,prefValue);
  58.     },
  59.  
  60.     array2JSON: function(array)
  61.     {
  62.         result = "{";
  63.         isFirst = true;
  64.         for (_key in array)
  65.         {
  66.             if (!isFirst)
  67.                 result += ",";
  68.             else
  69.                 isFirst = false;
  70.             result += _key+":"+array[_key];
  71.         }
  72.         result += "}";
  73.         return result;
  74.     },
  75.  
  76.     JSON2array: function(json)
  77.     {
  78.         result = new Array();
  79.         if (json!=null && json!="")
  80.         {
  81.             json = json.replace(/{|}/g,"");
  82.             elements = json.split(",");
  83.             for (f=0;f<elements.length;f++)
  84.             {
  85.                 parts = elements[f].split(":");
  86.                 result[parts[0]] = parts[1];
  87.             }
  88.         }
  89.         return result;
  90.     }
  91. }
  92.  
  93. var ro_cvds_daUtils = new deviantAnywhereUtils();
  94.